// models/user_model.dart
class UserModel {
  final String? token;
  final String? name;
  final String? password;
  final int? id;


  UserModel({this.token, this.name, this.id,this.password});

  // 转为 Map（用于保存）
  Map<String, dynamic> toJson() => {
    'token': token,
    'name': name,
    'id': id,
    'password': password,
  };

  // 从 Map 构建
  factory UserModel.fromJson(Map<String, dynamic> json) {
    return UserModel(
      token: json['token'],
      name: json['name'],
      id: json['id'],
      password: json['password'],
    );
  }

  // 是否已登录
  bool get isLoggedIn => token != null && token!.isNotEmpty;
}